package com.ynny.practice14.controller;

import com.ynny.practice14.entity.R;
import com.ynny.practice14.entity.Users;
import com.ynny.practice14.mapper.UsersMapper;
import com.ynny.practice14.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UsersController {
    @Autowired
    UsersService UsersService;
    @Autowired
    UsersMapper usersMapper;
    @RequestMapping("/login")
    public R login(@RequestBody Users users) {
        Users user = UsersService.login(users.getNumber(), users.getPassword());
        if (user != null) {
            return R.ok(user);
        }
        return R.fail(500, "用户名或密码错误");
    }
    @RequestMapping("/list")
    public R findAll() {
        return R.ok(usersMapper.selectAll());
    }

}
